package com.atguigu.mall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuDataFeign;
import com.atguigu.gmall.feign.product.ProductSkuDataFeign;
import com.atguigu.gmall.product.vo.SkuDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.math.BigDecimal;

/**
 * 详情页面
 * 商品详情数据
 */
@Controller
public class itemController {
    @Autowired
    private SkuDataFeign skuDataFeign;
    @Autowired
    private  ProductSkuDataFeign  productSkuDataFeign;
    @GetMapping("/{skuId}.html")
    public String getSkuDataVo(@PathVariable("skuId") Long skuId, Model model){
        Result<SkuDataVo> skuDetail = skuDataFeign.getSkuDataVo(skuId);
        //TODO 1 分类视图 categoryView1id  categoryView2id  categoryView3id
        //categoryView1name  categoryView2name   categoryView3name
        SkuDataVo skuDataVo=skuDetail.getData();
        model.addAttribute("categoryView", skuDataVo.getCategoryView());
        //TODO 2 sku的信息 （基本信息 ，图片信息）
        model.addAttribute("skuInfo",skuDataVo.getSkuInfo());
        //TODO 3 实时价格
        //TODO 因为价格要有时候变化 直接调用product服务
        BigDecimal bigDecimal = productSkuDataFeign.getPrice(skuId).getData();
        model.addAttribute("price",bigDecimal);
        //TODO 4所有的销售属性集合
        model.addAttribute("spuSaleAttrList",skuDataVo.getSpuSaleAttrList());
        //TODO 5 valueSkuJson
        model.addAttribute("valuesSkuJson",skuDataVo.getValuesSkuJson());

        return  "item/index";
    }

}
